package com.example.shop.goods.dao;

import com.example.shop.goods.dto.MerchantGoodsDetailBrowseInfo;
import com.example.shop.goods.enums.ShelfState;
import com.example.shop.goods.typehandler.ShelfStateTypeHandler;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface MerchantGoodsDetailBrowseInfoDao {
    public static final String ALL_FIELDS_SQL = GoodsBrowseInfoDao.ALL_FIELDS_SQL + "," +
            "g.bad_comment_number, g.favorable_comment_number, g.medium_comment_number," +
            "g.goods_video,g.goods_introduction, g.shelf_time, g.shelf_state ";
    @Results(id = "MerchantGoodsDetailBrowseInfoResultMap",value = {
            @Result(column = "goods_id",property = "goodsId"),
            @Result(column = "goods_id",property = "goodsDescriptionPicture",
                    many = @Many(select="com.example.shop.mapper.GoodsDescriptionPictureMapper.selectPictureById")),
            @Result(column = "goods_id",property = "goodsDetailsPicture",
                    many = @Many(select = "com.example.shop.mapper.GoodsDetailsPictureMapper.selectPictureById")),
            @Result(property = "goodsStyleList",
                    many = @Many(resultMap = "com.example.shop.goods.dao.GoodsStyleDao.GoodsStyleDaoResultMap")),
            @Result(column = "shelf_state",property = "shelfState",jdbcType = JdbcType.TINYINT,javaType = ShelfState.class,typeHandler = ShelfStateTypeHandler.class)
    })
    @Select(
            "select " + ALL_FIELDS_SQL +
            "from goods g join r_goods_class gc on g.goods_id = gc.goods_id " +
            "where g.goods_id = ${goodsId} and g.merchant_id = ${merchantId}")
    MerchantGoodsDetailBrowseInfo selectOne(@Param("merchantId") long merchantId,@Param("goodsId") long goodsId);
}
